<script type="text/javascript">

cek_username_toggle();
cek_jenis_customer();

$('select[name="tipe_username"]').change(function(e){
	cek_username_toggle();
});

function cek_username_toggle(){
	var toggle = $('select[name="tipe_username"]').find('option:selected').attr('value');
	if(toggle == 'auto'){
		$('input[name="username"]').attr('disabled',true);
	} else {
		$('input[name="username"]').removeAttr('disabled');
	}
}

$('select[name="jenis_customer"]').change(function(e){
	cek_jenis_customer();
});

function cek_jenis_customer(){
	var jenis_customer = $('select[name="jenis_customer"]').find('option:selected').attr('value');
	if(jenis_customer == 'perusahaan'){
		$('.perusahaan_only').show();
		$('.perusahaan_only').parent().find('h4').html('Info Perusahaan');
	} else {
		$('.perusahaan_only').hide();
		$('.perusahaan_only').parent().find('h4').html('Info Pelanggan');
	}
};

$('#register_form input[type="submit"]').click(function(e){
	e.preventDefault();
	$.ajax({
		type: 'POST',
		dataType: 'json',
		data: $('#register_form').serializeArray(),
		url: '<?php echo base_url().$this->uri->segment(1).'/ajax_register' ?>',
		success: function(data,status){
			if(data.status == 'sukses'){
				//alert(data.log_email);
				window.location.href = '<?php echo base_url().$this->uri->segment(1) ?>';
			} else {
				$('#error_info').find('div').html(data.error);
				$('#error_info').show();
			}
		}
	});
});
</script>
